<?php
/**
 * Created by PhpStorm.
 * Author: sitenv@aliyun.com
 * CreateTime: 2021/07/22 15:21
 * Blog：www.myblogs.xyz
 */

namespace app\admin\controller;


use think\facade\View;

class Apply extends Common
{
    public function index()
    {
        $app_id = input('param.app_id', 1, 'intval');
        $type = input('param.type',1,'intval');
        $apply_model = new \app\common\model\Apply();
        if (request()->isPost())
        {
            $data = input('post.');
            $data['update_time'] = NEW_TIME;
            $rows = $apply_model->operation($data, false);
            if (empty($rows)){
                $this->returnError('保存失败');
            }
            $this->returnSuccess('保存成功');
        }
        $apply_id = $apply_model->where(['apply_type'=>$type,'app_id'=>$app_id])
            ->order('update_time desc,apply_id desc')
            ->value('apply_id');
        $oldData = [];
        if (!empty($apply_id)){
            $oldData = $apply_model->getFind($apply_id);
        }
        View::assign([
            'app_id'=>$app_id,
            'type'=>$type,
            'oldData'=>$oldData,
        ]);
        return View::fetch();
    }

    public function updateList()
    {
        $apply_model = new \app\common\model\Apply();
        $data = $apply_model->getLists([], 10, 'update_time desc,apply_id desc');

        View::assign([
            'count'=>$data['count'],
            'list'=>$data['list'],
            'page'=>$data['page']
        ]);
        return View::fetch();
    }
}